package kr.saeildamil.androidStudy_second.brservice;

import kr.saeildamil.androidStudy_second.R;
import android.app.Activity;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class NapAlarm extends Activity {
	static final int NAPNOTI = 1;
	NotificationManager mNotify;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch29and30_napalarm);
		mNotify = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
	}

	public void mOnClick(View v) {
		Toast.makeText(this, "잘자라고 ㅋㅋ", Toast.LENGTH_LONG).show();
		v.postDelayed(new Runnable() {
			public void run() {
				Intent intent = new Intent(NapAlarm.this, NapEnd.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				PendingIntent content = PendingIntent.getActivity(
						NapAlarm.this, 0, intent, 0);

				Builder noti = new Notification.Builder(NapAlarm.this)
						.setTicker("좀 일어나ㅡㅡ")
						.setContentTitle("기상!!!!")
						.setContentText("아나 안일나면 밥없다")
						.setSmallIcon(R.drawable.moon)
						.setLargeIcon(
								BitmapFactory.decodeResource(
										getResources(),
										R.drawable.moon))
						.setContentIntent(content);

				mNotify.notify(NAPNOTI, noti.getNotification());

			}
		}, 5 * 1000);
	}
}
